home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Languages / Caml Light 0.7 / examples / calc / parser.mly < prev    next >
Encoding:
Text File  |  1995-06-01  |  610 b   |  27 lines  |  [TEXT/MPS ]

  1. %token <int> INT
  2. %token PLUS MINUS TIMES DIV
  3. %token LPAREN RPAREN
  4. %token EOL
  5.  
  6. %left PLUS MINUS        /* lowest precedence */
  7. %left TIMES DIV         /* medium precedence */
  8. %nonassoc UMINUS        /* highest precedence */
  9.  
  10. %start Main             /* the entry point */
  11. %type <int> Main
  12.  
  13. %%
  14.  
  15. Main:
  16.     Expr EOL                { $1 }
  17. ;
  18. Expr:
  19.     INT                     { $1 }
  20.   | LPAREN Expr RPAREN      { $2 }
  21.   | Expr PLUS Expr          { $1 + $3 }
  22.   | Expr MINUS Expr         { $1 - $3 }
  23.   | Expr TIMES Expr         { $1 * $3 }
  24.   | Expr DIV Expr           { $1 / $3 }
  25.   | MINUS Expr %prec UMINUS { - $2 }
  26. ;
  27.